﻿namespace DeYi.NuGet.JsonReturn
{
    /// <summary>
    /// 
    /// </summary>
    public class JsonReturn// : IActionResult
    {
        /// <summary>
        /// 
        /// </summary>
        public JsonReturn()
        {
            Status = ResultStatus.OK;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="status"></param>
        public JsonReturn(ResultStatus status)
        {
            Status = status;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="status"></param>
        /// <param name="code"></param>
        /// <param name="msg"></param>
        public JsonReturn(ResultStatus status, string code, string msg)
        {
            Status = ResultStatus.OK;
            Status = status;
            Code = code;
            Msg = msg;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <returns></returns>
        public static JsonReturn<T> CreateResult<T>(T data) => CreateResult(ResultStatus.OK, data);

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="status"></param>
        /// <returns></returns>
        public static JsonReturn<T?> CreateResult<T>(ResultStatus status) => CreateResult(status, default(T));

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="status"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static JsonReturn<T> CreateResult<T>(ResultStatus status, T data) => new(status) { Data = data };

        /// <summary>
        /// 
        /// </summary>
        /// <param name="code"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static JsonReturn CreateResult(string? code = null, string? msg = null) => CreateResult(ResultStatus.OK, code, msg);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="status"></param>
        /// <param name="code"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static JsonReturn CreateResult(ResultStatus status, string? code = null, string? msg = null) => new(status)
        {
            Code = code,
            Msg = msg
        };

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="context"></param>
        ///// <returns></returns>
        //public async Task ExecuteResultAsync(ActionContext context)
        //{
        //    if (context == null)
        //        throw new ArgumentNullException(nameof(context));
        //}

        /// <summary>
        /// 
        /// </summary>
        public ResultStatus Status { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Msg { get; set; }
    }

    /// <summary>
    /// 标准返回类型
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class JsonReturn<T> : JsonReturn
    {
        /// <summary>
        /// 
        /// </summary>
        public JsonReturn()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="status"></param>
        public JsonReturn(ResultStatus status) : base(status)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="status"></param>
        /// <param name="data"></param>
        public JsonReturn(ResultStatus status, T data) : base(status)
        {
            Data = data;
        }

        /// <summary>
        /// 
        /// </summary>
        public T Data { get; set; }
    }
}
